package com.print2;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service("a4")
public class TextPaper implements Paper {
    @Value("12")
    int words;
    @Value("6")
    int lines;

    public int getWords() {
        return words;
    }

    public void setWords(int words) {
        this.words = words;
    }

    public int getLines() {
        return lines;
    }

    public void setLines(int lines) {
        this.lines = lines;
    }

    @Override
    public void print(String s) {
        char cr[] = s.toCharArray();
        int w = 0, l = 0;//w表示当前行已经打印了几个字,l表示当前页已经打印了几行
        int p = 1;//p表示页号
        for (char c : cr) {
            System.out.print(c);
            w++;
            if (w == words) {//一行到头
                l++;
                w = 0;
                System.out.println();
                if (l == lines) {
                    System.out.println("---" + p + "---");
                    p++;
                    l = 0;
                }
            }
        }
        if (l > 0 || w > 0)
            System.out.println("\n---" + p + "---");
    }
}
